<template>
  <el-container>
    <el-header class="nav_header" height="50px">
      <div class="header_title" height="50px">
        <img
          src="@/assets/logo.png"
          width="70"
          height="20"
        />
        <h3 style="margin-left: 10px;">GKD后台管理</h3>
        <el-button
          @click="logout_click"
          type="danger"
          size="mini"
          plain
          style="height: 20px; margin-left: 50px"
          >退出</el-button
        >
      </div>
    </el-header>
    <el-divider></el-divider>
    <el-container>
      <el-aside width="200px">
        <el-menu v-bind:default-active="default_item" class="el-menu" @select="nav_select">
          <el-menu-item index="1">
            <i class="el-icon-menu"></i>
            <template #title>生成密钥</template>
          </el-menu-item>
          <el-menu-item v-show="show" index="2">
            <i class="el-icon-document"></i>
            <template #title>续费密钥</template>
          </el-menu-item>
          <el-menu-item index="3">
            <i class="el-icon-setting"></i>
            <template #title>查看密钥</template>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main class="content" v-loading="loading">
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  setup() {
    return{}
  },
  data() {
    var position = "1";
    if(location.pathname == "/home/extend_key"){
      position = 2;
    } else if(location.pathname == "/home/show_db") {
      position = 3
    }
    return {
      loading: false,
      show: false,
      default_item: position
    };
  },
  methods: {
    nav_select(index) {
      this.loading = true;
      if (index == 2) {
        this.$router.push("/home/extend_key");
      } else if (index == 3) {
        this.$router.push("/home/show_db");
      } else {
        this.$router.push("/home/generate_key");
      }
      this.loading = false;
    },
    logout_click() {
      this.$confirm("是否需要退出重新验证？", "提示", {
        confimButtonText: "退出",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        localStorage.clear();
        this.$router.push("/auth");
      });
    },
  },
};
</script>

<style>
.header_title {
  display: flex;
  flex-direction: row;
  text-align: center;
}
.header_title img  {
  vertical-align: middle;
	margin: auto 5px;
}

.header_title button  {
  vertical-align: middle;
	margin: auto 5px;
}

.nav_header {
  align-content: center;
  text-align: center;
}

.nav-menu {
  left: 0;
  text-align: center;
}

.content {
  text-align: center;
  margin-left: 20px;
}
</style>